package com.example.stock.controller;

import com.example.stock.comm.AssetEnum;
import com.example.stock.comm.FreqEnum;
import com.example.stock.comm.StrategyEnum;
import com.example.stock.entity.service.*;
import com.example.stock.service.IServiceRowData;
import com.example.stock.service.IServiceStatistics;
import com.example.stock.util.StockStatUtil;
import com.example.stock.vo.DataVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/api/index_analysis")
public class IndexAnalysisController {

    @Resource
    private IStockStatService IStockStatService;
    @Resource
    private IProBarIndexService IProBarIndexService;

    @Resource
    private IServiceStatistics serviceStatistics;

    @Resource
    private StockStatUtil stockStatUtil;
    @Resource
    private IServiceRowData serviceRowData;

    @RequestMapping("statistics_30")
    public Object statistics_30(String tsCode,@RequestParam(required = false) LocalDateTime startTime,String strategy) {
//        stockStatUtil.startStatistics();
        List<DataVo> closeData = serviceRowData.getRowDataWithFreq(tsCode, null, startTime, null, FreqEnum.MIN30, AssetEnum.INDEX);
        serviceStatistics.statistics(closeData, tsCode, FreqEnum.MIN30, StrategyEnum.getByNameExt(strategy));
        return "success!";
    }

    @RequestMapping("analysis_30")
    public Object analysis_30(int m,int n, String tsCode,@RequestParam(required = false) LocalDateTime startTime,String strategy) {
        List<DataVo> closeData = serviceRowData.getRowDataWithFreq(tsCode, null, startTime, null, FreqEnum.MIN30, AssetEnum.INDEX);
        Double finalMoney = IStockStatService.analysis(m,n, closeData,true, tsCode, FreqEnum.MIN30, StrategyEnum.getByNameExt(strategy));
        return finalMoney;
    }

    @RequestMapping("statistics_60")
    public Object statistics_60(String tsCode, LocalDateTime startTime,String strategy) {
        stockStatUtil.startStatistics();
        List<DataVo> closeData = serviceRowData.getRowDataWithFreq(tsCode, null, startTime, null, FreqEnum.MIN60, AssetEnum.INDEX);
        serviceStatistics.statistics(closeData, tsCode,FreqEnum.MIN60, StrategyEnum.getByNameExt(strategy));
        return "success!";
    }

    @RequestMapping("analysis_60")
    public Object analysis_60(int m,int n,String tsCode,@RequestParam(required = false)LocalDateTime startTime,String strategy) {
        List<DataVo> closeData = serviceRowData.getRowDataWithFreq(tsCode, null, startTime, null, FreqEnum.MIN60, AssetEnum.INDEX);
        Double finalMoney = IStockStatService.analysis(m,n, closeData,true, tsCode,FreqEnum.MIN60, StrategyEnum.getByNameExt(strategy));
        return finalMoney;
    }


}
